import axios from 'axios';
import {
	Method
} from './config';

const instance = axios.create({
	baseURL: "https://api.it120.cc/small4",
	timeout: 30000,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded'
	},
	transformRequest: [function(data) {
		let ret = ''
		for (let it in data) {
			ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
		}
		return ret
	}],
});

export function request(method, url, params) {
	switch (method) {
		case Method.GET:
			return GET(url, params);
		case Method.POST:
			return POST(url, params);
	}
}

function GET(url, params) {
	return instance.get(url, params)
};

function POST(url, params) {
	return instance.post(url, params)
}
